<template>
  <a-card :bordered="false">
    <detail-list title="基本信息">
      <detail-list-item term="商户名称">{{cashInfoDetails.sellerUserName }}</detail-list-item>
      <detail-list-item term="审核人">{{cashInfoDetails.adminUserName }}</detail-list-item>
      <detail-list-item term="提现订单金额(元)">{{cashInfoDetails.presentPrice/100}}</detail-list-item>
      <detail-list-item term="审核信息">{{cashInfoDetails.response==null?'无':cashInfoDetails.response}}</detail-list-item>
      <detail-list-item term="创建时间">{{cashInfoDetails.createTime}}</detail-list-item>
      <detail-list-item term="提现结果">
        <span v-if="result == 0">审核中</span>
        <span v-else-if="result == 1">提现成功</span>
        <span v-else-if="result == 2">提现失败</span>
      </detail-list-item>
    </detail-list>
    <a-divider style="margin-bottom: 32px"/>

    <div class="title">订单信息</div>
    <a-table
      style="margin-bottom: 24px"
      :columns="ordersColumns"
      :dataSource="ordersList">
    </a-table>
<!--    <a-divider style="margin-bottom: 32px"/>-->
    <div class="examples" >
      <a-button style="margin-left:30px;" size="large" @click="confirmCashInfo(cashInfoId)"  :disabled="successButton" type="primary" v-if="result == 0">同意</a-button>
      <a-button style="margin-left:35px;" size="large" @click="refuseCashInfo(cashInfoId)" :disabled="failButton" type="danger" v-if="result == 0">拒绝</a-button>
      <a-button style="margin-left:40px;" size="large" @click="closeTab()"  type="danger" v-if="result == 0">关闭</a-button>

    </div>

    <!-- 表单区域 -->
    <template-refuse ref="refuse" ></template-refuse>
  </a-card>
</template>

<script>
  import templateRefuse from '@/views/cashInfo/modules/TemplateRefuse'

  import PageLayout from '@/components/page/PageLayout'
  import STable from '@/components/table/'
  import DetailList from '@/components/tools/DetailList'
  import ABadge from "ant-design-vue/es/badge/Badge"
  import { getAction,postAction } from '@/api/manage'
  const DetailListItem = DetailList.Item
  export default {
    components: {
      PageLayout,
      ABadge,
      DetailList,
      DetailListItem,
      STable,
      'template-refuse': templateRefuse
    },
    data () {
      return {
        cashInfoId:{},
        successButton: false,
        failButton:false,
        //订单状态
        orderStatus:{},
        result:{},
        cashInfoDetails:{},
        ordersList:[],
        ordersColumns: [
          {
            title: '订单号',
            dataIndex: 'id',
            key: 'id'
          },
          {
            title: '店铺名称',
            dataIndex: 'shopId',
            key: 'shopId',
          },
          {
            title: '订单金额',
            dataIndex: 'buyPrice',
            key: 'buyPrice',
            customRender: text => {
              return text / 100
            },
            align:"center",
          },
          {
            title: '最终价格(元)',
            dataIndex: 'presentPrice',
            key: 'presentPrice',
            customRender: text => {
              return text / 100
            },
            align:"center",
          },

          {
            title: '付款时间',
            dataIndex: 'paymentTime',
            key: 'paymentTime',
          },
          {
            title: '成交时间',
              dataIndex: 'closingTime',
            key: 'closingTime',
          },
          {
            title: '状态',
            dataIndex: 'status',
            key: 'status',
            customRender: text => {
              if (text == 1){
                return '等待付款'
              } else if (text == 2){
                return '等待发货'
              } else if (text == 3){
                return '已发货'
              } else if (text == 4){
                return '已完成'
              } else if (text == 5){
                return '已关闭'
              } else if (text == 6){
                return '以评价'
              }
            }
          },
        ],
      }
    },
    created(){
      this.getCashInfo(this.$route.query.record.id);
    },
    mounted(){
    },
    activated(){
      this.getCashInfo(this.$route.query.record.id);
      this.successButton=false
      this.failButton=false
    },
    methods:{
      getCashInfo(ids) {
        let toParams = {id:ids};
        this.$nextTick(function () {
          getAction("/cash/detail",toParams )
            .then(res => {
              if (res.success) {
                this.cashInfoDetails = res.result
                console.log("this.cashInfoDetails ：" + res.result)
                this.result = res.result.result
                this.ordersList = res.result.orderList
                this.cashInfoId = res.result.id
              }
            })
            .catch(err => {
            });
        })
      },
      //关闭标签
      closeTab(){
        this.$router.back()
      },
      //同意
      confirmCashInfo(record){
        console.log("id：" + record)
        let obj = {cashInfoLogId:record};
        this.$nextTick(function () {
          postAction("/cash/confirm",obj)
            .then(res => {
              if (res.success) {
                  this.successButton=true
                  this.$router.back()
                  this.$notification.success({
                    message: '审核结果',
                    description: `提现 : `+"审核通过",
                  });
              }
              else{
                this.$notification.success({
                    message: '审核结果',
                    description: `提现 : `+res.message,
                  });
              }
              
            }).catch(err => {
          });
        })
        this.closeTab()
      },

      refuseCashInfo(record) {
        console.log("id ：" + record)
        this.$refs.refuse.show(record)

      }
    },
    computed: {
      // title () {
      //   return this.$route.meta.title
      // }
    },
  }
</script>

<style lang="scss" scoped>
  .title {
    color: rgba(0,0,0,.85);
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 16px;
  }
  .examples {
    text-align: center;
  }
</style>